# coding=utf-8
import  os,xlrd,sys,io,xlwt,DegreeConvert

excelPath = 'E:\\PythonProjects\\africa2\\africa\\doc\\africa\\data\\modified\\Copy of error reviesd.xls'
excelFile=xlrd.open_workbook(excelPath)

workbook = xlwt.Workbook(encoding = 'ascii')
worksheet = workbook.add_sheet('sheet1')
worksheet.write(0, 0, label='x')
worksheet.write(0, 1, label='y')
worksheet.write(0, 2, label='id')
sheet=excelFile.sheet_by_index(1)

wRowIndex =1
for i in range(0,sheet.nrows):
    row = sheet.row_values(i)
    print i
    for j in range(1,sheet.ncols):
        if not row[j]:
            break
        row[j] = row[j].replace(u'\xa0', u'').replace(u'\u200e', u'')
        # print row[j]
        # print row[j].find(',')
        if row[j].find(',')>0:
            data = row[j].split(',')
        elif row[j].find('.')>0:
            step =0
            if row[j].find('-')>0:
                step =1
            index = row[j].rfind('.')
            data_y = row[j][:index-2-step].strip()
            data_x = row[j][index-2-step:].strip()
            data =[data_y,data_x]
        print 'data:',data
        y = DegreeConvert.getRadians(data[0])
        x = DegreeConvert.getRadians(data[1])
        print x,y
        worksheet.write(wRowIndex, 0, label=str(x))
        worksheet.write(wRowIndex, 1, label=str(y))
        worksheet.write(wRowIndex, 2, label=row[0])
        wRowIndex= wRowIndex+1
workbook.save('E:\\PythonProjects\\africa2\\africa\\doc\\africa\\data\\modified\\points1.xls')
